<?php
// +---------------------------------------------------------------------+
// | OneBase    | [ WE CAN DO IT JUST THINK ]                            |
// +---------------------------------------------------------------------+
// | Licensed   | http://www.apache.org/licenses/LICENSE-2.0 )           |
// +---------------------------------------------------------------------+
// | Author     | Bigotry <3162875@qq.com>                               |
// +---------------------------------------------------------------------+
// | Repository | https://gitee.com/Bigotry/OneBase                      |
// +---------------------------------------------------------------------+

namespace app\index\controller;
use think\Rsa;
/**
 * 前端首页控制器
 */
class Index extends IndexBase
{
    // 首页
    public function index()
    {
        if($this->isMobile()){
            return $this->fetch('index');
        }else{
            return $this->fetch('indexs');
        }
    }
    //判断是否手机页面访问
    public function isMobile(){
        // 如果有HTTP_X_WAP_PROFILE则一定是移动设备
        if (isset ($_SERVER['HTTP_X_WAP_PROFILE'])){
            return TRUE;
        }
        // 如果via信息含有wap则一定是移动设备,部分服务商会屏蔽该信息
        if (isset ($_SERVER['HTTP_VIA'])){
            return stristr($_SERVER['HTTP_VIA'], "wap") ? TRUE : FALSE;// 找不到为flase,否则为TRUE
        }
        // 判断手机发送的客户端标志,兼容性有待提高
        if (isset ($_SERVER['HTTP_USER_AGENT'])) {
            $clientkeywords = array (
                'mobile',
                'nokia',
                'sony',
                'ericsson',
                'mot',
                'samsung',
                'htc',
                'sgh',
                'lg',
                'sharp',
                'sie-',
                'philips',
                'panasonic',
                'alcatel',
                'lenovo',
                'iphone',
                'ipod',
                'blackberry',
                'meizu',
                'android',
                'netfront',
                'symbian',
                'ucweb',
                'windowsce',
                'palm',
                'operamini',
                'operamobi',
                'openwave',
                'nexusone',
                'cldc',
                'midp',
                'wap'
            );
            // 从HTTP_USER_AGENT中查找手机浏览器的关键字
            if (preg_match("/(" . implode('|', $clientkeywords) . ")/i", strtolower($_SERVER['HTTP_USER_AGENT']))){
                return TRUE;
            }
        }
        if (isset ($_SERVER['HTTP_ACCEPT'])){ // 协议法，因为有可能不准确，放到最后判断
            // 如果只支持wml并且不支持html那一定是移动设备
            // 如果支持wml和html但是wml在html之前则是移动设备
            if ((strpos($_SERVER['HTTP_ACCEPT'], 'vnd.wap.wml') !== FALSE) && (strpos($_SERVER['HTTP_ACCEPT'], 'text/html') === FALSE || (strpos($_SERVER['HTTP_ACCEPT'], 'vnd.wap.wml') < strpos($_SERVER['HTTP_ACCEPT'], 'text/html')))){
                return TRUE;
            }
        }
        return FALSE;
    }
    // 详情
    public function details($id = 0)
    {
        
        $where = [];
        
        !empty((int)$id) && $where['a.id'] = $id;
        
        $data = $this->logicArticle->getArticleInfo($where);
        
        $this->assign('article_info', $data);
        
        $this->assign('category_list', $this->logicArticle->getArticleCategoryList([], true, 'create_time asc', false));
        
        return $this->fetch('details');
    }
    // 首页
    public function sh_job()
    {
        $data=$this->param;
        $id=$data['wid'];
        $info=db('work')->where('id',$id)->find();
        $info['cont']=preg_replace('/\n/', '<br>', $info['cont']);
        $info['education']=db('education')->where('education_id',$info['education_id'])->value('name');
        $info['experience']=db('experience')->where('experience_id',$info['experience_id'])->value('name');
        if(!empty($info['position_id'])){
            $info['position']=db('position_cat')->where('id',$info['position_id'])->value('catname');
        }
        $cinfo=db('company')->field('company,type,num')->where('user_id',$info['user_id'])->find();
        $cinfo['typeName']=db('company_type')->where('id',$cinfo['type'])->value('name');
        $cinfo['numName']=db('company_num')->where('id',$cinfo['num'])->value('name');
        $cinfo['headimg']=db('user')->where('id',$info['user_id'])->value('headimg');
        $this->assign('info', $info);
        $this->assign('cinfo', $cinfo);
        return $this->fetch('jobInfo');
    }
    //简历详情
    public function resumeInfo(){
        $data=$this->param;
        $data['user_id']=10006;
        $info=db('resume')->where(array('user_id'=>$data['user_id']))->find();
        $info['cont']=preg_replace('/\n/', '<br>', $info['cont']);
        if(!empty($info['position_id'])){
            $info['positionName']=db('position_cat')->where('id',$info['position_id'])->value('catname');
        }
        if(!empty($info['education_id'])){
            $info['education']=db('education')->where('education_id',$info['education_id'])->value('name');
        }
        $info['headimg']=db('user')->where('id',$info['user_id'])->value('headimg');
        $info['age']=countages($info['birthday']);
        $info['gzjy']=countages($info['joinTime']);
        $info['experienceList']=db('resume_experience')->where('resume_id',$info['resume_id'])->select();
        $info['educationList']=db('resume_education')->where('resume_id',$info['resume_id'])->select();
        $this->assign('info', $info);
        return $this->fetch('resumeInfo');
    }
//    //测试推送
//    public function tuisong(){
//        $res=jpush('10006',4,'恭喜您，您有新的MDC到账啦！');
//        var_dump($res);exit;
//    }
//    //测试rsa
//    public function rsajm(){
//        $public='/www/wwwroot/app.lptxhr.com/public/rsa/pub.key';
//        $pravite='/www/wwwroot/app.lptxhr.com/public/rsa/priv.key';
//        import("rsa.Rsa");
//        $rsa = new \Rsa($public,$pravite);
//        $str=$rsa->encrypt('10006');
//        var_dump($str);exit;
//    }
//    /**
//     * 邮件发送
//     */
    public function demoSendEmail()
    {
        $str="<table width=\"700\" align=\"center\" cellpadding=\"0\" cellspacing=\"0\" style=\"margin-top:30px;border:1px solid rgb(230,230,230);font-size:12px;font-family:simsun;\">
    <tbody><tr>
        <td style=\"width:648px;\">
            <table class=\"out-table\" border=\"0\" width=\"648\" cellspacing=\"0\" cellpadding=\"0\" style=\"\">
                <tbody><tr>
                    <td width=\"30\"></td>
                    <td width=\"640\" style=\"padding:20px 0 23px 0;\">
                        <a href=\"http://app.lptxhr.com\" rel=\"noopener\" target=\"_blank\"><img src=\"http://app.lptxhr.com/static/module/index/images/logo.png\" style=\"margin-left:10px;border:none;line-height:0\">
                        </a>
                    </td>
                    <td width=\"30\"></td>
                </tr>
            </tbody></table>
        </td>
    </tr>
    <tr>
        <td>
            <table>
                <tbody><tr>
                    <td width=\"56\" align=\"right\" style=\"border: 0;padding:0;margin: 0;\">
                        <img src=\"https://image1.highpin.cn/Image/Active/20190325Edm/20190325Edm-02.jpg\" style=\"line-height: 0\">
                    </td>
                    <td width=\"600\" style=\"margin: 0;padding: 0;vertical-align: top;\">
                        <table>
                            <tbody><tr>
                                <td align=\"left\" width=\"400\">
                                    <p style=\"padding:0 10px;margin-top:10px;margin-bottom:0;font-size: 20px;font-family: 'Microsoft YaHei';font-weight: bold;color:#333;vertical-align: top;\">高级软件工程师</p>
                                </td>

                            </tr>
                            <tr>
                                <td colspan=\"2\">
                                    <p style=\"margin-left:10px;margin-right:10px;padding-bottom:16px;margin-top:10px;margin-bottom:0;border-bottom: 1px solid #e7e7e7;\">
                                        <span style=\"vertical-align: middle;font-size:16px;color:#dd4e41;font-weight: bold;font-family: 'Microsoft YaHei';\">20-40万</span>
                                        <img src=\"https://image1.highpin.cn/Image/Active/20190325Edm/split-line.jpg?v=20190328\" style=\"width:1px;height:14px;color: #e7e7e7;margin: 0 6px;vertical-align: middle;\">
                                        <span style=\"vertical-align: middle;font-size:16px;color:#666;font-family: 'Microsoft YaHei';\">某医学机器人公司</span>
                                        <img src=\"https://image1.highpin.cn/Image/Active/20190325Edm/split-line.jpg?v=20190328\" style=\"width:1px;height:14px;color: #e7e7e7;margin: 0 6px;vertical-align: middle;\">
                                        <span style=\"vertical-align: middle;font-size:16px;color:#666;font-family: 'Microsoft YaHei';\">四川-成都</span>
                                    </p>
                                    <p style=\"padding: 0 10px;margin:22px 0 0 0; line-height: 24px;font-size: 14px;font-family: 'Microsoft YaHei';\">
                                        面试公司：<a><span style=\"color:green;font-size: 15px\">四川环球浩业</span></a>
                                    </p>
									<p style=\"padding: 0 10px;margin:5px 0 0 0; line-height: 24px;font-size: 14px;font-family: 'Microsoft YaHei';\">
                                        面试时间：<span style=\"color:#999;font-size: 15px\">2018-12-25 下午 5:00</span>
                                    </p>
									<p style=\"padding: 0 10px;margin:5px 0 0 0; line-height: 24px;font-size: 14px;font-family: 'Microsoft YaHei';\">
                                        面试地址：<span style=\"color:#999;font-size: 15px\">基于软件设计需求进行方案设计及代码实</span>
                                    </p>
									<p style=\"padding: 0 10px;margin:5px 0 0 0; line-height: 24px;font-size: 14px;font-family: 'Microsoft YaHei';\">
                                        联系电话：<span style=\"color:#999;font-size: 15px\">18381687117</span>
                                    </p>
									<p style=\"padding: 0 10px;margin:5px 0 0 0; line-height: 24px;font-size: 14px;font-family: 'Microsoft YaHei';\">
                                        注意事项：<span style=\"color:#999;font-size: 15px\">基于软件设计需求进行方案设计及代码实现。</span>
                                    </p>
                                </td>
                            </tr>
                        </tbody></table>
                    </td>
                    <td width=\"56\" align=\"left\" style=\"border: 0;padding:0;margin: 0;\">
                        <img src=\"https://image1.highpin.cn/Image/Active/20190325Edm/20190325Edm-03.jpg\" style=\"line-height: 0\">
                    </td>
                </tr>
            </tbody></table>
        </td>
    </tr>
    <tr>
        <td>
            <table>
                <tbody><tr>
                    <td width=\"28\"></td>
                    <td width=\"643\" align=\"bottom\" style=\"border: 0;padding:0;margin: 0;\">
                        <img src=\"https://image1.highpin.cn/Image/Active/20190325Edm/20190325Edm-04.jpg\" style=\"line-height: 0\">
                    </td>
                    <td width=\"27\"></td>
                </tr>
            </tbody></table>
        </td>
    </tr>
</tbody></table>";
        $data = send_email('296411083@qq.com', '诸葛聘', $str);
        var_dump($data);exit;
    }
    /**
     * 火币接口
    */
    public function hbsearch(){

        $config=[
            "apiKey"=>"a69416d7-8994-4768-9ce0-495cf67d580e",
            "apiSecret"=>"5FAF5885A5892C16CB2605C3D68F3659",
            "passphrase"=>"hqhy1106",
        ];
        import("hb.SwapApi");
        $instrumentId = "EOS-USD-SWAP";
        $rsa = new \SwapApi($config);
        $s=$rsa->getSpecificPosition($instrumentId);
        var_dump($s);exit;
    }
    public function mysqlSave(){
        //db('company_type')->insert(array('name'=>'混合所有制'));
    }
}
